package com.hs.demos.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hs.demos.entity.Order;
import com.hs.demos.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/saveOrder")
    public String saveOrder() {
        Order order = new Order();
        order.setOrderNo("11111");
        order.setUserId("1");
        order.setCreateTime(LocalDateTime.of(2024, 3, 3, 0, 0, 0));
        orderService.save(order);
        return "success";
    }

    @GetMapping("/list")
    public List<Order> list() {

        return orderService.list(Wrappers.<Order>lambdaQuery()
                .ge(Order::getCreateTime, LocalDateTime.of(2024, 3, 1,0, 0, 0))
                .le(Order::getCreateTime, LocalDateTime.of(2024, 4, 30, 0, 0, 0))
        );
    }
}
